﻿using System;
using System.Collections.Generic;
using System.Text;
using BlueLotus7.Contract;
using BlueLotus7.Common;

namespace BlueLotus7.External.Contract
{
    public class BaseAccountStatusRecord : IValidate
    {
        protected Guid key;
        protected Guid ownerKey;
        protected AccountStatus status;
        protected DateTime createdStamp;

        #region Property

        /// <summary>
        /// The key.
        /// </summary>
        public Guid Key
        {
            get { return key; }
        }

        /// <summary>
        /// The owner key.
        /// </summary>
        public Guid OwnerKey
        {
            get { return ownerKey; }
            set { ownerKey = value; }
        }

        /// <summary>
        /// The content.
        /// </summary>
        public AccountStatus Status
        {
            get { return status; }
        }

        /// <summary>
        /// The created stamp.
        /// </summary>
        public DateTime CreatedStamp
        {
            get { return createdStamp; }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="ownerKey">The owner key.</param>
        /// <param name="status">The status.</param>
        public BaseAccountStatusRecord(Guid ownerKey, AccountStatus status)
        {
            this.ownerKey = ownerKey;
            this.status = status;
            this.key = Guid.NewGuid();
            this.createdStamp = DateTime.Now;
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="ownerKey">The owner key.</param>
        /// <param name="status">The status.</param>
        /// <param name="createdStamp">The created stamp.</param>
        public BaseAccountStatusRecord(Guid key, Guid ownerKey, AccountStatus status, DateTime createdStamp)
        {
            this.ownerKey = ownerKey;
            this.status = status;
            this.key = key;
            this.createdStamp = createdStamp;
        }

        #endregion

        #region IValidate

        public bool IsValid
        {
            get
            {
                try
                {
                    Validate();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }

        public void Validate()
        {
            if (Validator.IsZeroDateTime(createdStamp))
            {
                throw new InvalidObjectException("createdStamp");
            }
        }

        #endregion

    }
}
